import Config from "react-native-config";

export const HoleType = [{id:1, name:"左洞"}, {id:2, name:"右洞"}];

export function holeType2Name(t) {
    let arr = HoleType.filter((item)=>item.id == t);
    if(arr && arr.length > 0) {
        return arr[0].name;
    } else {
        return "";
    }
}

export const OperationResult = {
    SUCCESS: 1,
    FAILED: 0
}

export const RegisterType = {
    UN_REGISTER: 0,
    REGISTER_NO_NET:    1,
    REGISTER_SUCCESS:   2,
    REGISTER_ERROR: 3
};

export const ProductID = {
    GateWay: "GateWay",
    LOOP: "LoopController",
    SMART: "SmartMeter",
};

export const DeviceModelID = {
    GateWay: "jt_gate_way",
    LOOP: "jt_loop_controller",
    SMART: "jt_smart_meter",
}

export const ValidType = {
    INVALID: 0,
    VALID: 1
}

export const onlineStatus = {
    ONLINE: 2,
    OFFLINE: 1
}

export const InterfaceType = {
    SERIAL_DIRECT: 1,
    USB_SERIAL: 2,
    EMULATE: 3
}

export const SerialConfig = {
    baudRate: 9600,             // 波特率9600
    parity: 0,                  // 0为无校验
    // parity: 2,                  // 2为偶校验
    dataBits: 8,                // 数据位8
    stopBits: 1,                 // 停止位1
}

export const MeterConfig = {
    baudRate: 9600,             // 波特率9600
    parity: 0,                  // 无校验
    dataBits: 8,                // 数据位8
    stopBits: 1,                 // 停止位1
}

export const DevicePort = {
    LOOPCONTROLLER_PORT:2,
    SMART_PORT:0,
}
 
export const MessageDirection = {
    REQUEST: 0,
    RESPONSE: 1
}

export const MessageKey = {  
    SERVERKEY: 0,
    GATEKEY: 1,
    NOKEY: 2
}

export const Version_Protocol = "1.0";

export const Default_Retry_Count = 3;

export const AUTOINIT_INTERVAL = Config.AUTOINIT_INTERVAL || 300000
export const MQTT_ASYNC_INTERVAL = Config.MQTT_ASYNC_INTERVAL || 600000
export const LOOP_CONTROLLER_QUERY_INTERVAL = Config.LOOP_CONTROLLER_QUERY_INTERVAL || 60000
export const METER_QUERY_INTERVAL = Config.METER_QUERY_INTERVAL || 600000

export const Topic_Control = {
    topic: "/sys/${serverId}/${gateId}/${productId}/thing/gate/control",
    method: "thing.gate.control",
    direct: MessageDirection.REQUEST,
};
export const Topic_Control_Reply = {
    topic: "/sys/${serverId}/${gateId}/${productId}/thing/gate/control_reply",
    method: "thing.gate.control_reply",
    direct: MessageDirection.RESPONSE,
};
export const Topic_Strategy = {
    topic: "/sys/${serverId}/${gateId}/${productId}/thing/gate/strategy", 
    method: "thing.gate.strategy",
    direct: MessageDirection.REQUEST,
};
export const Topic_Strategy_Reply = {
    topic: "/sys/${serverId}/${gateId}/${productId}/thing/gate/strategy_reply", 
    method: "thing.gate.strategy_reply",
    direct: MessageDirection.RESPONSE,
};
export const Topic_Tunnel = {
    topic: "/sys/${serverId}/${gateId}/${productId}/thing/gate/tunnel", 
    method: "thing.gate.tunnel",
    direct: MessageDirection.REQUEST,
};
export const Topic_Tunnel_Reply = {
    topic: "/sys/${serverId}/${gateId}/${productId}/thing/gate/tunnel_reply", 
    method: "thing.gate.tunnel_reply",
    direct: MessageDirection.RESPONSE,
};
export const Topic_Loop = {
    topic: "/sys/${serverId}/${gateId}/${productId}/thing/gate/loop", 
    method: "thing.gate.loop",
    direct: MessageDirection.REQUEST,
};
export const Topic_Loop_Reply = {
    topic: "/sys/${serverId}/${gateId}/${productId}/thing/gate/loop_reply", 
    method: "thing.gate.loop_reply",
    direct: MessageDirection.RESPONSE,
};
export const Topic_Adjust = {
    topic: "/sys/${serverId}/${gateId}/${productId}/thing/gate/adjust", 
    method: "thing.gate.adjust",
    direct: MessageDirection.REQUEST,
};
export const Topic_Adjust_Reply = {
    topic: "/sys/${serverId}/${gateId}/${productId}/thing/gate/adjust_reply", 
    method: "thing.gate.adjust_reply",
    direct: MessageDirection.RESPONSE,
};
export const Topic_UpdateIp = {
    topic: "/sys/${serverId}/${gateId}/thing/server/update_ip", 
    method: "thing.gate.update_ip",
    direct: MessageDirection.REQUEST,
};
export const Topic_UpdateIp_Reply = {
    topic: "/sys/${serverId}/${gateId}/thing/server/update_ip_reply", 
    method: "thing.gate.update_ip_reply",
    direct: MessageDirection.RESPONSE,
};
export const Topic_Property = {
    topic: "/sys/${serverId}/${gateId}/thing/gate/property", 
    method: "thing.gate.property",
    direct: MessageDirection.REQUEST,
};
export const Topic_Property_Reply = {
    topic: "/sys/${serverId}/${gateId}/thing/gate/property_reply", 
    method: "thing.gate.property_reply",
    direct: MessageDirection.RESPONSE,
};
export const Topic_Report = {
    topic: "/sys/${serverId}/${gateId}/thing/gate/report", 
    method: "thing.gate.report",
    direct: MessageDirection.REQUEST,
};
export const Topic_Report_Reply = {
    topic: "/sys/${serverId}/${gateId}/thing/gate/report_reply", 
    method: "thing.gate.report_reply",
    direct: MessageDirection.RESPONSE,
};

export const Topic_Master = {
    topic: "/sys/${serverId}/${gateId}/${productId}/thing/gate/master",
    method: "thing.gate.master",
    direct: MessageDirection.REQUEST,
}

export const Topic_Master_Reply = {
    topic: "/sys/${serverId}/${gateId}/${productId}/thing/gate/master_reply",
    method: "thing.gate.master_reply",
    direct: MessageDirection.RESPONSE,
}

export const Topic_Update_LightMode = {
    topic: "/sys/${serverId}/${gateId}/${productId}/thing/gate/update_lightmode",
    method: "thing.gate.update_lightmode",
    direct: MessageDirection.REQUEST,
};
export const Topic_Update_LightMode_Reply = {
    topic: "/sys/${serverId}/${gateId}/${productId}/thing/gate/update_lightmode_reply",
    method: "thing.gate.update_lightmode_reply",
    direct: MessageDirection.RESPONSE,
};

export const Topic_Debug = {
    topic: "/sys/${serverId}/${gateId}/thing/gate/debug",
    method: "thing.gate.debug",
    direct: MessageDirection.REQUEST,
};
export const Topic_Debug_Reply = {
    topic: "/sys/${serverId}/${gateId}/thing/gate/debug_reply",
    method: "thing.gate.debug_reply",
    direct: MessageDirection.RESPONSE,
};

export const Topic_Async = {
    topic: "/sys/${serverId}/${gateId}/thing/gate/async",
    method: "thing.gate.async",
    direct: MessageDirection.REQUEST,
};
export const Topic_Async_Reply = {
    topic: "/sys/${serverId}/${gateId}/thing/gate/async_reply",
    method: "thing.gate.async_reply",
    direct: MessageDirection.RESPONSE,
};

export const Topic_Update_Meter_Config = {
    topic: "/sys/${serverId}/${gateId}/thing/gate/update_smart_meter_config",
    method: "thing.gate.update_smart_meter_config",
    direct: MessageDirection.REQUEST,
};

export const Topic_Update_Meter_Config_Reply = {
    topic: "/sys/${serverId}/${gateId}/thing/gate/update_smart_meter_config_reply",
    method: "thing.gate.update_smart_meter_config_reply",
    direct: MessageDirection.RESPONSE,
};

export const Topic_Meter_Property = {
    topic: "/sys/${serverId}/${gateId}/thing/gate/smart_meter_property",
    method: "thing.gate.smart_meter_property",
    direct: MessageDirection.REQUEST,
};

export const Topic_Meter_Property_Reply = {
    topic: "/sys/${serverId}/${gateId}/thing/gate/smart_meter_property_reply",
    method: "thing.gate.smart_meter_property_reply",
    direct: MessageDirection.RESPONSE,
};

export const Topic_Map = {
    "control": Topic_Control,
    "control_reply": Topic_Control_Reply,
    "strategy": Topic_Strategy,
    "strategy_reply": Topic_Strategy_Reply,
    "tunnel": Topic_Tunnel,
    "tunnel_reply": Topic_Tunnel_Reply,
    "loop": Topic_Loop,
    "loop_reply": Topic_Loop_Reply,
    "adjust": Topic_Adjust,
    "adjust_reply": Topic_Adjust_Reply,
    "update_ip": Topic_UpdateIp,
    "update_ip_reply": Topic_UpdateIp_Reply,
    "property": Topic_Property,
    "property_reply": Topic_Property_Reply,
    "report": Topic_Report,
    "report_reply": Topic_Report_Reply,
    "master": Topic_Master,
    "master_reply": Topic_Master_Reply,
    "update_lightmode": Topic_Update_LightMode,
    "update_lightmode_reply": Topic_Update_LightMode_Reply,
    "debug": Topic_Debug,
    "debug_reply": Topic_Debug_Reply,
    "async": Topic_Async,
    "async_reply": Topic_Async_Reply,
    "update_smart_meter_config": Topic_Update_Meter_Config,
    "update_smart_meter_config_reply": Topic_Update_Meter_Config_Reply,
    "smart_meter_property": Topic_Meter_Property,
    "smart_meter_property_reply": Topic_Meter_Property_Reply,
}

export const Adjust_Model = {
    ADJUST_DIRECT_LIGHT: 1,
    ADJUST_STRATEGY_LIGHT: 2,
}

export const Control_Level = {
    LEVEL_TUNNEL: 1,
    LEVEL_SEGMENT: 2,
    LEVEL_GROUP: 3,
    LEVEL_LOOP: 4,
    LEVEL_STRATEGY: 99,
}

export const MQTT_CONNECT_STATUS = {
    CONNECT_NONE:0,
    CONNECT_SUCCESS:1,
    CONNECT_CLOSE:2,
    CONNECT_ERROR:3
}

export const ACK_Type = {
    NO_ACK:0,
    ACK:1,
}